package com.luocj.muke.demo.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.luocj.muke.demo.R;
import com.luocj.muke.demo.model.CountDownModel;

import java.util.ArrayList;

public class CountDownAdapter extends RecyclerView.Adapter<CountDownAdapter.Holder> {

    private static final String TAG = CountDownAdapter.class.getSimpleName();
    private Context mContext;
    private ArrayList<CountDownModel> mData = new ArrayList<>();

    public CountDownAdapter(Context context, ArrayList<CountDownModel> data) {
        this.mContext = context;
        this.mData = data;
    }

    @NonNull
    @Override
    public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.item_count_down, parent, false);
        Holder holder = new Holder(inflate);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull Holder holder, int position) {
        holder.name.setText(mData.get(position).getName());
        holder.countTime.setText(mData.get(position).getTime());
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public void notifyData() {
//        for (int i = 0; i < mData.size(); i++) {
//           mData
//            Log.i(TAG, "notifyData: " + mData.get(i).getTime());
//        }

        notifyDataSetChanged();
    }

    public class Holder extends RecyclerView.ViewHolder {
        TextView countTime;
        TextView name;

        public Holder(View itemView) {
            super(itemView);
            countTime = itemView.findViewById(R.id.tv_count_time);
            name = itemView.findViewById(R.id.tv_name);

        }
    }
}
